//
//  JHUser.m
//  Demo_Pods
//
//  Created by gjh on 2021/3/8.
//  Copyright © 2021 gjh. All rights reserved.
//

#import "JHUser.h"

@implementation JHUser

- (instancetype)initWithFirstName:(NSString *)firstName lastName:(NSString *)lastName email:(NSString *)email age:(NSInteger)age {
    self = [super init];
    if (self) {
        _firstName = firstName;
        _lastName = lastName;
        _email = email;
        _age = age;
    }
    return self;
}

+ (void)getUsers:(void (^)(NSArray<JHUser *> * _Nonnull))usersBlock {
    
    // 获取数据
    NSInteger count = 11;
    // 初始化一个数组
    NSMutableArray<JHUser *> *userArray = [NSMutableArray arrayWithCapacity:count];
    
    for (NSInteger i = 0; i < count; i++) {
        NSString *string = [NSString stringWithFormat:@"%ld", (long)i];
        
        JHUser *user = [[JHUser alloc] initWithFirstName:string lastName:string email:string age:i];
        
        [userArray addObject:user];
    }
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (usersBlock) {
            usersBlock(userArray);
        }        
    });
}

@end
